package com.mingmen.canting.chushizhang;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.mingmen.canting.R;
import com.mingmen.canting.adapter.MyLabelAdapter;
import com.mingmen.canting.adapter.ZhenBanMySortLabelAdapter;
import com.mingmen.canting.adapter.ZhenBanSortAllLabelAdapter;
import com.mingmen.canting.adapter.ZhenBanSortLabelAdapter;
import com.mingmen.canting.base.BaseBean;
import com.mingmen.canting.defineview.PayPassDialog;
import com.mingmen.canting.defineview.PayPassView;
import com.mingmen.canting.dialog.ButtomDialogView;
import com.mingmen.canting.fragment.BaseFragment;
import com.mingmen.canting.http.callback.StringCallback;
import com.mingmen.canting.httpconfig.HttpResponse;
import com.mingmen.canting.model.CommdityColletModel;
import com.mingmen.canting.model.GetMarkModel;
import com.mingmen.canting.model.ShopListModel;
import com.mingmen.canting.model.ZhenBanLeftBean;
import com.mingmen.canting.popwindow.PopupWindowCompat;
import com.mingmen.canting.util.GsonUtil;
import com.mingmen.canting.util.MyStringUtils;
import com.mingmen.canting.util.SharePreferenceUtil;
import com.mingmen.canting.util.ToolList;
import com.mingmen.canting.zhenban.ZhenBanLeftAdapter;
import com.mingmen.canting.zhenbanlibrary.CheckListener;
import com.mingmen.canting.zhenbanlibrary.ClassifyLastAdapter;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import de.greenrobot.event.EventBus;
import okhttp3.Call;
import okhttp3.Response;

@SuppressLint("ValidFragment")
public class ChuShiZhangNewDingDanFragment extends BaseFragment implements CheckListener, ZhenBanLeftAdapter.OnItemClickListener, View.OnClickListener, ClassifyLastAdapter.OnItemClickListener, CompoundButton.OnCheckedChangeListener, ZhenBanSortLabelAdapter.OnItemClickListener {

    @BindView(R.id.rv_sort)
    RecyclerView rvSort;
    Unbinder unbinder;

    private ZhenBanLeftAdapter mSortAdapter;

//    private ZhenBanMySortDetailFragment mSortDetailFragment;

    String getData;
    String token;

    int position;

    List<ZhenBanLeftBean.ChildrenBean> childrenBeanList = new ArrayList<>();
    ZhenBanLeftBean zhenBanLeftBean;
    Gson gson;
    @BindView(R.id.img_shousuo)
    ImageView img_shousuo;

    Context mContext;


    LinearLayout layout_nodata;

    private ClassifyLastAdapter mAdapter;
    List<ShopListModel.DataBean> data = new ArrayList<>();
    @BindView(R.id.layout_selectall)
    LinearLayout layout_selectall;
    @BindView(R.id.tv_total)
    TextView tv_total;
    @BindView(R.id.text_del)
    TextView text_del;
    int myflag = 0;
    int select_shop = 0;


    @BindView(R.id.recycle_liebiao)
    RecyclerView recycle_liebiao;
    @BindView(R.id.layout_nodata1)
    LinearLayout layout_nodata1;

    @BindView(R.id.cb_check)
    CheckBox cb_check;
    @BindView(R.id.zhankai)
    ImageView zhankai;
    @BindView(R.id.recycle_biaoqian)
    RecyclerView recycle_biaoqian;
    ZhenBanSortLabelAdapter linkLabelAdapter;


    @BindView(R.id.layout_more)
    LinearLayout layout_more;

    @BindView(R.id.layout_list)
    LinearLayout layout_list;
    int flag_pop = 0;
    @BindView(R.id.layout_label)
    LinearLayout layout_label;
    @BindView(R.id.layout_liebiao)
    RelativeLayout layout_liebiao;
    @BindView(R.id.btn_submit)
    Button btn_submit;
    String date_Send;
    List<String> deleteList = new ArrayList<>();
    String applyId;
    String getCategoryId = "";
    ZhenBanMySortLabelAdapter zhenBanMySortLabelAdapter;
    ZhenBanSortAllLabelAdapter zhenBanAllLabelAdapter;
    String modify;
    List<String> modiDataList = new ArrayList<>();
    @Override
    public View initView() {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fr_zhenbannew_dingdan, null);
        TextView card_title_tv = (TextView) view.findViewById(R.id.card_title_tv);
        unbinder = ButterKnife.bind(this, view);
        card_title_tv.setText(getData);
        if (!EventBus.getDefault().isRegistered(this)) {//加上判断
            EventBus.getDefault().register(this);
        }
        mContext = getActivity();
        token = (String) SharePreferenceUtil.get(getActivity(), "token", "");
        applyId = (String) SharePreferenceUtil.get(getActivity(), "applyId", "");
        layout_list = view.findViewById(R.id.layout_list);
        layout_nodata = view.findViewById(R.id.layout_nodata);
        gson = new Gson();
        rvSort = (RecyclerView) view.findViewById(R.id.rv_sort);
        rvSort.setLayoutManager(new LinearLayoutManager(getActivity()));

        modify = (String) SharePreferenceUtil.get(getActivity(), "modify", "");
        initLinstener();


        Log.d("getDatagetData", getData);
        Log.d("onCreateView", "onCreateView");
        if (childrenBeanList.size() > 0) {
            childrenBeanList.clear();
        }

        zhenBanLeftBean = new ZhenBanLeftBean();
        zhenBanLeftBean = gson.fromJson(getData, ZhenBanLeftBean.class);
        mSortAdapter = new ZhenBanLeftAdapter(getActivity(), childrenBeanList);
        rvSort.setAdapter(mSortAdapter);

        childrenBeanList.addAll(zhenBanLeftBean.getChildren());
        Log.d("zhenBanLeftBean", childrenBeanList.size() + "");

        Log.d("childrenBeanList", childrenBeanList.size() + "");
        mSortAdapter.setDataList(childrenBeanList);
        mSortAdapter.setOnItemClickListener(this);
        mSortAdapter = new ZhenBanLeftAdapter(getActivity(), childrenBeanList);
        rvSort.setAdapter(mSortAdapter);
        mSortAdapter.setOnItemClickListener(this);

        zhenBanMySortLabelAdapter = new ZhenBanMySortLabelAdapter(getActivity(), data);
        final GridLayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 3);
        recycle_biaoqian.setLayoutManager(mLayoutManager);
        recycle_biaoqian.setAdapter(zhenBanMySortLabelAdapter);
        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.custom_divider));
        recycle_biaoqian.addItemDecoration(divider);
        zhenBanMySortLabelAdapter.setOnItemClickListener(new ZhenBanMySortLabelAdapter.OnItemClickListener() {
            @Override
            public void onItemLabelClickListener(View view, int pos, List<ShopListModel.DataBean> myLiveList) {
                zhenBanMySortLabelAdapter.setCheckedPosition(pos);
                recycle_liebiao.scrollToPosition(pos);
            }


        });
        zhenBanAllLabelAdapter = new ZhenBanSortAllLabelAdapter(getActivity(), data);
        zhenBanAllLabelAdapter.setOnItemClickListener(new ZhenBanSortAllLabelAdapter.OnItemClickListener() {
            @Override
            public void onItemLabelClickListener(View view, int pos, List<ShopListModel.DataBean> myLiveList) {
                zhenBanMySortLabelAdapter.setCheckedPosition(pos);
                recycle_liebiao.scrollToPosition(pos);
            }

        });

//        popWindowCreate(childrenBeanList);
//        linkLabelAdapter.setOnItemClickListener(this);

        if (childrenBeanList.size() == 0) {
            layout_list.setVisibility(View.GONE);
            layout_nodata.setVisibility(View.VISIBLE);
        } else {
            layout_list.setVisibility(View.VISIBLE);
            layout_nodata.setVisibility(View.GONE);
        }
        recycle_liebiao.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter = new ClassifyLastAdapter(getActivity(), data);
        recycle_liebiao.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(this);
        if (childrenBeanList.size() == 0) {
            layout_nodata.setVisibility(View.VISIBLE);
            layout_list.setVisibility(View.GONE);
        } else {
            getcategoryList(token, childrenBeanList.get(0).getCategoryId());
            getCategoryId = childrenBeanList.get(0).getCategoryId();
        }

        return view;
    }

    public void initLinstener() {
        cb_check.setOnCheckedChangeListener(this);


    }

    public void getcategoryList(String token, String categoryId) {
        HttpResponse.getFenLeiShop(token, categoryId, new StringCallback(getActivity()) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                Log.d("getCodegetStr", s);
                if (data.size() > 0) {
                    data.clear();
                }
                Gson gson = new Gson();
                ShopListModel shopListModel = new ShopListModel();
                shopListModel = gson.fromJson(s, ShopListModel.class);
                data.addAll(shopListModel.getData());
                mAdapter.setDataList(data);
                mAdapter.notifyDataSetChanged();

                zhenBanAllLabelAdapter.setDataList(data);
                zhenBanAllLabelAdapter.notifyDataSetChanged();
                zhenBanMySortLabelAdapter.setDataList(data);
                zhenBanMySortLabelAdapter.notifyDataSetChanged();
                if (data.size() == 0) {

                    recycle_biaoqian.setVisibility(View.GONE);
                    layout_selectall.setVisibility(View.GONE);
                    layout_liebiao.setVisibility(View.GONE);
                    layout_nodata1.setVisibility(View.VISIBLE);
                    layout_label.setVisibility(View.GONE);
//                    recycle_biaoqian.setVisibility(View.GONE);
                } else {
                    layout_selectall.setVisibility(View.VISIBLE);
                    layout_nodata1.setVisibility(View.GONE);
                    recycle_biaoqian.setVisibility(View.VISIBLE);
                    layout_liebiao.setVisibility(View.VISIBLE);
                    layout_label.setVisibility(View.VISIBLE);
                }

                if (data.size() < 6) {
                    layout_more.setVisibility(View.INVISIBLE);
                } else {
                    layout_more.setVisibility(View.VISIBLE);
                }
                popWindowCreate(data);
            }
        });
        mAdapter.setDataList(data);

    }

    @Override
    public void initData() {

    }


    public static ChuShiZhangNewDingDanFragment getInstance(String title) {
        ChuShiZhangNewDingDanFragment sf = new ChuShiZhangNewDingDanFragment();
        sf.getData = title;
        Log.d("DingDandkdkdkd", title);

        return sf;
    }


    String myreceiveposition;

    private void setChecked(int position, boolean isLeft) {
        Log.d("p-------->", String.valueOf(position));
        mSortAdapter.setCheckedPosition(position);
        myreceiveposition = String.valueOf(position);

    }


    @Override
    public void check(int position, boolean isScroll) {
        setChecked(position, isScroll);
    }


    @Override
    public void onItemClickListener(View view, int pos, List<ZhenBanLeftBean.ChildrenBean> myLiveLists) {
        mSortAdapter.setCheckedPosition(pos);
        getcategoryList(token, myLiveLists.get(pos).getCategoryId());
        getCategoryId = myLiveLists.get(pos).getCategoryId();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        }
    }

    @Override
    public void onDestroy() {
        unbinder.unbind();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }

        super.onDestroy();
    }

    List<String> applyList = new ArrayList<>();

    @Override
    public void onItemClickListener1(View view, int pos, List<ShopListModel.DataBean> myLiveList) {
        switch (view.getId()) {
            case R.id.checkbox:
            case R.id.layout_checkbox:
                if (myLiveList.get(pos).getApplyAmount() == 0) {
                    Toast.makeText(getActivity(), "请选择商品数量", Toast.LENGTH_SHORT).show();
                    myLiveList.get(pos).setChecked(false);
                    mAdapter.notifyDataSetChanged();
                } else {
                    for (ShopListModel.DataBean cart : data) {
                        if (cart.isChecked()) {   //是否勾上去了

                            Log.d("勾选上了", "勾选上了");
                            JSONObject jsonObject = new JSONObject();
                            JSONObject modiData = new JSONObject();

                            try {
                                jsonObject.put("commodityId", cart.getCommodityId());
                                jsonObject.put("commodityAmount", cart.getApplyAmount() + "");
                                jsonObject.put("categoryId", "0");
                                jsonObject.put("mark", cart.getMark());
                                if (modify.equals("1")) {
                                    modiData.put("detailId", "0");
                                    modiData.put("commodityId", cart.getCommodityId());

                                    modiData.put("mark", cart.getMark());
                                } else if (modify.equals("2")) {
                                    modiData.put("detailId", cart.getDetailId());
                                    modiData.put("commodityId", cart.getCommodityId());
                                    modiData.put("amount", cart.getApplyAmount() + "");
                                    modiData.put("mark", cart.getMark());
                                }

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            modiDataList.add(modiData.toString());
                            deleteList.add(cart.getDetailId());

                            applyList.add(jsonObject.toString());
                            ToolList.removeDuplicateWithOrder(applyList);
                            tv_total.setText("已选购" + applyList.size() + "");
                            text_del.setVisibility(View.VISIBLE);
                            Log.d("applyListapplyListapplyList", applyList.toString());

                            myflag = 0;
                            if (data.size() == applyList.size()) {
                                cb_check.setChecked(true);
                            }
                            Log.d("datasize", data.size() + "");
                            Log.d("applyList", applyList.size() + "");
                            deleteList.add(cart.getDetailId());
                            Log.d("deleteList", deleteList.toString());
                            ToolList.removeDuplicateWithOrder(deleteList);
                            ToolList.removeDuplicateWithOrder(modiDataList);
                        } else {
                            Log.d("取消勾选", "取消勾选");
                            myflag = 1;
                            cb_check.setChecked(false);
                            if (applyList.size() > 0) {
                                for (int i = 0; i < applyList.size(); i++) {
                                    if (applyList.get(i).contains(cart.getCommodityId())) {
                                        applyList.remove(i);
                                    }
                                }
                                text_del.setVisibility(View.VISIBLE);
                            } else if (applyList.isEmpty()) {
                                text_del.setVisibility(View.GONE);
                            } else if (applyList.size() == 0) {
                                text_del.setVisibility(View.GONE);
                            }

                            ToolList.removeDuplicateWithOrder(applyList);
                            Log.d("applyListapply", applyList.toString());
                            tv_total.setText("已选购" + applyList.size() + "");
                            if (deleteList.size() > 0) {
//                                deleteList.add(cart.getDetailId());
                                for (int i = 0; i < deleteList.size(); i++) {
                                    if (deleteList.get(i).contains(cart.getDetailId())) {
                                        deleteList.remove(i);
                                    }
                                }
                            }

                            ToolList.removeDuplicateWithOrder(deleteList);
                            if (modiDataList.size() > 0) {
                                for (int i = 0; i < modiDataList.size(); i++) {
                                    if (modiDataList.get(i).contains(cart.getCommodityId())) {
                                        modiDataList.remove(i);
                                    }
                                }
                            }
                            ToolList.removeDuplicateWithOrder(modiDataList);
                        }
                    }
                }

                break;
            case R.id.img_add:
            case R.id.tv_add:
            case R.id.tv_reduce:
                select_shop = myLiveList.get(pos).getApplyAmount();
                break;
            case R.id.text_beizhu:

                createPopwindow(pos, myLiveList);

                break;
            case R.id.img_collect:

                getCollect(token, pos, myLiveList.get(pos).getCommodityId(), myLiveList);

                break;

            case R.id.tv_num:
                payDialog3(pos, myLiveList);
                break;

        }
    }


    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            int flag = 0;
            myflag = 0;
            Log.d("applyListapplyList", applyList.toString());
            for (int i = 0; i < data.size(); i++) {
                if (data.get(i).getApplyAmount() > 0) {
                    flag = data.get(i).getApplyAmount();
                }
            }
            if (flag == 0) {
                Toast.makeText(mContext, "请选择商品数量", Toast.LENGTH_SHORT).show();
                cb_check.setChecked(false);
            } else {
                for (int i = 0; i < data.size(); i++) {
                    if (data.get(i).getApplyAmount() > 0) {
                        cb_check.setChecked(true);
                        data.get(i).setChecked(true);
                        text_del.setVisibility(View.VISIBLE);
                        JSONObject jsonObject = new JSONObject();
                        JSONObject modiData = new JSONObject();
                        try {
                            jsonObject.put("commodityId", data.get(i).getCommodityId());
                            jsonObject.put("commodityAmount", data.get(i).getApplyAmount() + "");
                            jsonObject.put("categoryId", "0");
                            jsonObject.put("mark", data.get(i).getMark());

                            if (modify.equals("1")) {
                                modiData.put("detailId", "0");
                                modiData.put("commodityId", data.get(i).getCommodityId());
                                modiData.put("amount", data.get(i).getApplyAmount() + "");
                                modiData.put("mark", data.get(i).getMark());
                            } else if (modify.equals("2")) {
                                modiData.put("detailId", data.get(i).getDetailId());
                                modiData.put("commodityId", data.get(i).getCommodityId());
                                modiData.put("amount", data.get(i).getApplyAmount() + "");
                                modiData.put("mark", data.get(i).getMark());
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        applyList.add(jsonObject.toString());
                        ToolList.removeDuplicateWithOrder(applyList);
                        deleteList.add(data.get(i).getDetailId());
                        ToolList.removeDuplicateWithOrder(deleteList);
                        modiDataList.add(modiData.toString());
                        ToolList.removeDuplicateWithOrder(modiDataList);
                    } else {
                        data.get(i).setChecked(false);
                    }

                }
            }

            Log.d("AllSelectAllApplist", applyList.toString());
//                        showTotalPrice();
            tv_total.setText("已选购" + applyList.size() + "");
            mAdapter.notifyDataSetChanged();
        } else {
            if (myflag == 0) {
                for (int i = 0; i < data.size(); i++) {
                    data.get(i).setChecked(false);
                }
                applyList.clear();
                mAdapter.notifyDataSetChanged();
                Log.d("NoSelectAllApplist", applyList.toString());
                tv_total.setText("已选购" + applyList.size() + "");
                deleteList.clear();
                modiDataList.clear();
            } else {

            }

        }
    }

    public void getCollect(String token, int pos, String commodityId, List<ShopListModel.DataBean> myLiveList) {
        HttpResponse.setCommodityCollect(token, commodityId, new StringCallback(getActivity()) {
            @Override
            public void onSuccess(String s, Call call, Response response) {

                Log.d("setCommodityCollect", s);
                BaseBean baseBean = new BaseBean();
                baseBean = GsonUtil.GsonToBean(s, BaseBean.class);
                if (baseBean.getCode() == 0) {
                    CommdityColletModel commdityColletModel = GsonUtil.GsonToBean(s, CommdityColletModel.class);
                    myLiveList.get(pos).setCollectionFlag(commdityColletModel.getData().getData());
                    mAdapter.notifyDataSetChanged();
                    EventBus.getDefault().post(20);
                    Toast.makeText(getActivity(), commdityColletModel.getMessage(), Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity(), "请求失败", Toast.LENGTH_SHORT).show();
                }


            }
        });

    }

    @OnClick({R.id.zhankai, R.id.img_shousuo, R.id.layout_more, R.id.btn_submit, R.id.text_del})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.zhankai:
                rvSort.setVisibility(View.VISIBLE);
                zhankai.setVisibility(View.GONE);
                flag_pop = 0;
                break;
            case R.id.img_shousuo:
                flag_pop = 1;
                rvSort.setVisibility(View.GONE);
                zhankai.setVisibility(View.VISIBLE);
                break;
            case R.id.layout_all:

                break;
            case R.id.layout_more:

                popupWindow.showAsDropDown(layout_more);
                break;
            case R.id.btn_submit:
                if (applyList.size() == 0) {
                    Toast.makeText(mContext, "请选择商品数量", Toast.LENGTH_SHORT).show();
                } else {
//                    Toast.makeText(mContext, "成功", Toast.LENGTH_SHORT).show();
                    String submitDate = (String) SharePreferenceUtil.get(getActivity(), "submitDate", "");
                    Log.d("submitDate", submitDate);
                    submitData(submitDate);

                }

                break;
            case R.id.text_del:
                String delStr = MyStringUtils.returnStringBuffer(deleteList);
                if (deleteList.size() == 0) {
                    Toast.makeText(mContext, "请选择商品数量", Toast.LENGTH_SHORT).show();
                } else {
                    Log.d("deleteList", deleteList.toString());
//                sendData(token, applyId, "0", modiDataList.toString(), delStr);
                    sendData(token, applyId, "0", "", delStr, "1");
                }

                break;
        }
    }

    public void sendData(String token, String applyId, String role, String modiData, String deleteData, String flag) {
        HttpResponse.getModify(token, applyId, role, modiData, deleteData, new StringCallback(getActivity()) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                BaseBean baseBean = new BaseBean();
                baseBean = GsonUtil.GsonToBean(s, BaseBean.class);
                if (baseBean.getCode() == 0) {
              /*      if (flag.equals("1")) {
                        getcategoryList(token, getCategoryId);
                    }*/
              if (modify.equals("1")){
                  getActivity().finish();
              }else {
//                  getcategoryList(token, getCategoryId);
                  getActivity().finish();
              }

                }
                Toast.makeText(mContext, baseBean.getMessage() + "", Toast.LENGTH_SHORT).show();

            }
        });
    }

    /**
     * 3 自定义方式
     */
    private void payDialog3(int pos, List<ShopListModel.DataBean> myLiveList) {
        final PayPassDialog dialog = new PayPassDialog(getActivity(), R.style.dialog_pay_theme);
        //弹框自定义配置
        dialog.setAlertDialog(false)
                .setWindowSize(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.4f)
                .setOutColse(false) //点击外部是否消失
                .setGravity(R.style.dialogOpenAnimation, Gravity.BOTTOM);
        //组合控件自定义配置
        dialog.getPayViewPass()
                .setHintText("数量")
                .setForgetText("密码忘记?")
                .setForgetColor(getResources().getColor(R.color.colorAccent))
                .setForgetSize(16)
                .setPayClickListener(new PayPassView.OnPayClickListener() {
                    @Override
                    public void onPassFinish(String password) {
                        //6位输入完成回调
//                        Toast.makeText(mContext, "输入内容:" + password, Toast.LENGTH_SHORT).show();
                        Log.d("passwordpassword", password);

                        if (password.equals("")) {

                        } else {
                            Integer int_count = Integer.valueOf(password);
                            myLiveList.get(pos).setApplyAmount(int_count);
                            mAdapter.notifyDataSetChanged();
                        }


                    }

                    @Override
                    public void onPayClose() {
                        dialog.dismiss();
                        //关闭回调
                    }

                    @Override
                    public void onPayForget() {
                        dialog.dismiss();

                    }
                });
    }

    public void createPopwindow(int pos, List<ShopListModel.DataBean> myLiveList) {
        MyLabelAdapter myLabelAdapter;
        LayoutInflater layoutInflater = LayoutInflater.from(getActivity());

        View view1 = layoutInflater.inflate(R.layout.dialog_bottom, null);

        ButtomDialogView bottomSheetDialog = new ButtomDialogView(getActivity(), view1, true, true);
        bottomSheetDialog.setContentView(R.layout.toast_dialog);
        bottomSheetDialog.show();
        RecyclerView recycle_biaoqian = view1.findViewById(R.id.recycle_biaoqian);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
        recycle_biaoqian.setLayoutManager(gridLayoutManager);
        EditText verify_et = view1.findViewById(R.id.verify_et);

        TextView text_submit = view1.findViewById(R.id.text_submit);
        myLabelAdapter = new MyLabelAdapter(getActivity());
        recycle_biaoqian.setAdapter(myLabelAdapter);
        List<String> mystr = new ArrayList<>();

        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.custom_divider));
        recycle_biaoqian.addItemDecoration(divider);
        ImageView img_close = view1.findViewById(R.id.img_close);
        img_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomSheetDialog.dismiss();
            }
        });

        HttpResponse.getMark(token, "4", new StringCallback(getActivity()) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                Log.d("getMarkgetMark", s);

                GetMarkModel getMarkModel = new GetMarkModel();
                getMarkModel = GsonUtil.GsonToBean(s, GetMarkModel.class);
                for (int i = 0; i < getMarkModel.getData().size(); i++) {
                    mystr.add(getMarkModel.getData().get(i).getMark());
                    myLabelAdapter.setDataList(mystr);
                }

                myLabelAdapter.setOnItemClickListener(new MyLabelAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClickListener(View view, int pos, List<String> myLiveList) {
                        Log.d("ZHenBanMYsortDetail", myLiveList.get(pos));
                        myLabelAdapter.setCheckedPosition(pos);
                        verify_et.setText(myLiveList.get(pos));
                    }
                });
            }
        });

        text_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myLiveList.get(pos).setMark(verify_et.getText().toString());
                bottomSheetDialog.dismiss();
                mAdapter.notifyDataSetChanged();
            }
        });

    }

    @Override
    public void onItemLabelClickListener(View view, int pos, List<ShopListModel.DataBean> myLiveList) {
        linkLabelAdapter.setCheckedPosition(pos);
        recycle_liebiao.scrollToPosition(pos);
    }

    PopupWindowCompat popupWindow;

    public void popWindowCreate(List<ShopListModel.DataBean> childrenBeanList) {
        popupWindow = new PopupWindowCompat(getActivity());
        View view1 = LayoutInflater.from(getActivity()).inflate(R.layout.zhenban_label, null);
        popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.setContentView(view1);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        View view_pop = view1.findViewById(R.id.view_pop);
        if (flag_pop == 0) {
            view_pop.setVisibility(View.VISIBLE);
        } else {
            view_pop.setVisibility(View.GONE);
        }
        RecyclerView recycle_biaoqian = view1.findViewById(R.id.recycle_biaoqian);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
        recycle_biaoqian.setLayoutManager(gridLayoutManager);
        ZhenBanSortAllLabelAdapter zhenBanSortAllLabelAdapter = new ZhenBanSortAllLabelAdapter(getActivity(), data);
        recycle_biaoqian.setAdapter(zhenBanSortAllLabelAdapter);
        zhenBanSortAllLabelAdapter.setDataList(childrenBeanList);
        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.custom_divider));
        recycle_biaoqian.addItemDecoration(divider);
        zhenBanSortAllLabelAdapter.setOnItemClickListener(new ZhenBanSortAllLabelAdapter.OnItemClickListener() {
            @Override
            public void onItemLabelClickListener(View view, int pos, List<ShopListModel.DataBean> myLiveList) {
                rvSort.scrollToPosition(pos);
                mSortAdapter.setCheckedPosition(pos);
                zhenBanSortAllLabelAdapter.setCheckedPosition(pos);
                recycle_liebiao.scrollToPosition(pos);
            }


        });
    }

    String deleteData = "";
    public void submitData(String submitDate) {
        HttpResponse.submitData(token, submitDate, "1", applyList.toString(), "8点之前", new StringCallback(getActivity()) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                Log.d("SortDetailFragment", s);
                BaseBean baseBean = new BaseBean();

                baseBean = GsonUtil.GsonToBean(s, BaseBean.class);
                if (baseBean.getCode() == 0) {
                    EventBus.getDefault().post(11);
                    EventBus.getDefault().post(31);
                    EventBus.getDefault().post(30);
                    getActivity().finish();
                }
                Toast.makeText(getActivity(), baseBean.getMessage() + "", Toast.LENGTH_SHORT).show();
            }
        });

    }

    public void onEventMainThread(Integer integer) {


    }


}